package com.fanketly.funacg2.ui.viewmodels

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.fanketly.funacg2.data.TAG
import com.fanketly.funacg2.data.model.WorkList
import com.fanketly.funacg2.data.paging.WorkBySearchPagingSource
import com.fanketly.funacg2.data.repo.AudioRepo
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@HiltViewModel
class SearchViewModel @Inject constructor(private val repo: AudioRepo) : ViewModel() {
    private var source = WorkBySearchPagingSource("", repo)


    fun search(name: String) {
        source = WorkBySearchPagingSource(name, repo)
    }

    val pager = Pager(
        PagingConfig(
            pageSize = 20, initialLoadSize = 20, enablePlaceholders = true, maxSize = 200
        )
    ) {
        source
    }.flow.cachedIn(viewModelScope)


    init {
        Log.i(TAG, "SearchViewModel: ")
    }

}